home *** CD-ROM | disk | FTP | other *** search
- /* See the file Distribution for distribution terms.
- (c) Copyright 1994 Ari Halberstadt */
-
- #pragma once
-
- #if WINTER_SHELL
- #include "LLHandleLib.h"
- #include "TimeLib.h"
- #else /* WINTER_SHELL */
- #include "ThreadUtil.h"
- #include "ExceptionLib.h"
- #endif /* WINTER_SHELL */
-
- /* Define as 1 to save certain low-memory global variables on context
- switches. See warning in ThreadLib.c for more details. */
- #define THREAD_SAVE_GLOBALS (0)
-
- /* version of the thread library */
- #define THREAD_VERSION (1)
-
- /* default stack size */
- #define THREAD_STACK_SIZE (0x2000)
-
- /* function called as thread's entry point */
- typedef void (*ThreadProcType)(void *data);
-
- /* information needed in SegmentLib.c */
- typedef struct {
- Ptr stack_top; /* highest address in thread's stack */
- Ptr stack_bottom; /* lowest address in thread's stack */
- Ptr register_a6; /* value of thread's register a6 */
- } ThreadStackFrameType;
-
- /* data describing a thread */
- typedef struct {
- LLType next; /* next thread */
- jmp_buf env; /* for context switch */
- Ptr stack; /* thread's stack */
- TicksType wake; /* when to wake thread */
- ThreadProcType entry; /* thread's entry point */
- ThreadProcType suspend; /* called when thread is suspended */
- ThreadProcType resume; /* called when thread is resumed */
- ExceptionType exception; /* saved state of gExeception global variable */
- void *data; /* data to pass to thread's call-backs */
- #if THREAD_SAVE_GLOBALS
- Ptr heapEnd; /* value of HeapEnd low-memory global */
- Ptr applLimit; /* value of ApplLimit low-memory global */
- Ptr hiHeapMark; /* value of HiHeapMark low-memory global */
- #endif /* THREAD_SAVE_GLOBALS */
- } ThreadType, *ThreadPtr, **ThreadHandle;
-
- Boolean ThreadValid(ThreadHandle thread);
-
- size_t ThreadStackSpace(ThreadHandle thread);
- void ThreadStackFrame(ThreadHandle thread, ThreadStackFrameType *frame);
-
- short ThreadCount(void);
- ThreadHandle ThreadMain(void);
- ThreadHandle ThreadActive(void);
- ThreadHandle ThreadFirst(void);
- ThreadHandle ThreadNext(ThreadHandle thread);
-
- ThreadHandle ThreadSchedule(void);
- void ThreadActivate(ThreadHandle thread);
- void ThreadYield(TicksType sleep);
- TicksType ThreadYieldInterval(void);
-
- ThreadHandle ThreadBeginMain(ThreadProcType suspend, ThreadProcType resume,
- void *data);
- ThreadHandle ThreadBegin(ThreadProcType entry,
- ThreadProcType suspend, ThreadProcType resume,
- void *data, size_t stack_size);
- void ThreadEnd(ThreadHandle thread);
-